<?php


namespace App\Http\Controllers\Customer;


use App\Http\Controllers\Controller;
use App\Http\Requests\Customer\Docking\UpdateRequest;
use App\Http\Searchs\Customer\DockingSearch;
use App\Repositories\CustomerDocking;

class DockingController extends Controller
{
    /**
     * @var CustomerDocking
     * @author luffyzhao@vip.126.com
     */
    private $customerDocking;

    /**
     * DockingController constructor.
     * @param CustomerDocking $customerDocking
     * @author luffyzhao@vip.126.com
     */
    public function __construct(CustomerDocking $customerDocking)
    {
        $this->customerDocking = $customerDocking;
    }

    /**
     * @param DockingSearch $search
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function index(DockingSearch $search)
    {
        return $this->response(
            $this->customerDocking->paginate(
                $search->toArray()
            )
        );
    }

    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function edit($id)
    {
        return $this->response(
            $this->customerDocking->edit($id)
        );
    }

    /**
     * @param UpdateRequest $request
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @throws \Throwable
     * @author luffyzhao@vip.126.com
     */
    public function update(UpdateRequest $request, $id){
        return $this->response(
            $this->customerDocking->update($id, $request->only(['callback', 'authorities']))
        );
    }
}